/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package argtrust.apiexamples;

import java.lang.System;

import aima.core.logic.fol.parsing.FOLParser;
import aima.core.logic.fol.parsing.ast.Sentence;
import aima.core.logic.fol.domain.FOLDomain;

import argtrust.logic.FOLNaturalDeduction;
import argtrust.logic.FOLKnowledgeBase;
import argtrust.logic.InferenceRule;
import argtrust.logic.InferenceNode;
import argtrust.argsys.ArgumentationSystem;
import argtrust.argsys.ArguingNode;
import argtrust.belief.BeliefBase;
import argtrust.trustnet.Agent;
import argtrust.trustnet.TrustNet;
import argtrust.trustnet.TrustNode;
import argtrust.measure.LevelMeasure;
/**
 *
 * @author Yuqing Tang
 */
public class NaturalDeductionExample {

    public static void main(String[] args) {
        //Create FOL domain:
        FOLDomain domain = new FOLDomain();
        domain.addConstant("John");
        domain.addConstant("Jane");
        domain.addConstant("Bill");
        domain.addConstant("Elizabeth");
        domain.addFunction("Mother");
        domain.addPredicate("Knows");


        //Create FOL KB
        FOLParser parser = new FOLParser(domain);
        Sentence knowsJohn = parser.parse("Knows(John,x)");
        Sentence knowsJohnB = parser.parse("Knows(John,b)");
        Sentence johnKnowsJane = parser.parse("Knows(y,Mother(y))");
        FOLKnowledgeBase kb = new FOLKnowledgeBase();

        //Add content to KB:
        kb.addFact(knowsJohn);
        //...
        InferenceRule aRule = new InferenceRule();
        aRule.P_(knowsJohn);
        aRule.C_(knowsJohn);
        kb.addRule(aRule);


        //Test on deductions
        FOLNaturalDeduction deduct_sys = new FOLNaturalDeduction();
        deduct_sys.acceptKnowledgeBase(kb);
        InferenceNode inf_net = deduct_sys.getInferenceNet(knowsJohn);
        inf_net.debug_print(System.out);
        System.out.println("end test");


//        //Argumentation system:
//        ArgumentationSystem arg_sys = new ArgumentationSystem(kb);
//        ArguingNode arg_graph = arg_sys.createArgGraph(knowsJohnB);
//        arg_graph.debug_print(System.out);

        //Agent:
        Agent john = new Agent("john");
        Agent alice = new Agent("alice");
        Agent dave = new Agent("dave");

        //Belief base:
        BeliefBase belief_base = new BeliefBase();
        belief_base.believe(john, aRule, 0.8);
        belief_base.believe(dave, aRule, 0.7);
        belief_base.believe(dave, knowsJohn, 0.9);

        //Accept the knowledge in beliefbase into natural deuction system:
        kb.acceptKnowledgeBase(belief_base.getFactSet(), belief_base.getRuleSet());
        deduct_sys.acceptKnowledgeBase(kb);

        //TrustNetwork:
        TrustNet trust_net = new TrustNet();
        trust_net.trust(dave, john, new LevelMeasure(0.8));
        trust_net.trust(john, dave, new LevelMeasure(0.7));
    }
}
